/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.terramagnet.mvcframework.resource.thumbnails;

import java.awt.Dimension;
import net.coobird.thumbnailator.ThumbnailParameter;
import net.coobird.thumbnailator.name.Rename;

/**
 * 大小固定的资源缩略图命名.
 *
 * @author lip
 */
public class DimensionRename extends Rename {

    private final Dimension dimension;

    public DimensionRename(Dimension dimension) {
        this.dimension = dimension;
    }

    @Override
    public String apply(String fileName, ThumbnailParameter param) {
        StringBuilder builder = new StringBuilder();
        int indexOfDot = fileName.lastIndexOf('.');

        builder.append(indexOfDot < 0 ? fileName : fileName.substring(0, indexOfDot))
            .append("-")
            .append(dimension.width)
            .append("x")
            .append(dimension.height);

        if (indexOfDot >= 0) {
            builder.append(fileName.substring(indexOfDot));
        }

        return builder.toString();

    }

}
